package xyz.robinbingo.dailybill.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @author Robin
 * @date 2018-08-24 14:17
 **/
class Generator {

    private static final String PACKAGE_NAME = "xyz.robinbingo.dailybill";
    private static final String OUTPUT_DIR = "D:\\Workspace\\[mine]\\daily-bill\\src\\main\\java";
    private static final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";

    static void g(String url, String username, String password, String[] tableNames) {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setActiveRecord(false)
                .setAuthor("Robin")
                .setOutputDir(OUTPUT_DIR)
                .setFileOverride(true)
                .setServiceName("%sService");

        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
                .setUrl(url)
                .setUsername(username)
                .setPassword(password)
                .setDriverName(DRIVER_NAME);

        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(true)
                .setEntityLombokModel(false)
                .setNaming(NamingStrategy.underline_to_camel)
                .setInclude(tableNames);

        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent(PACKAGE_NAME);

        new AutoGenerator()
                .setGlobalConfig(globalConfig)
                .setDataSource(dataSourceConfig)
                .setStrategy(strategyConfig)
                .setPackageInfo(packageConfig)
                .execute();
    }
}
